/**
 *  增加或减少(输入) 选择的商品
 */
define(function(require,exports,module) {
    var myPub = require('./public');
    var priceCount = require('./submit_calcLastPrice');
    var coupon = require('./submit_coupon');

    var oWrap = $('.js_wrap');
    var oMyPayType = $('.js_myPayType');    // 支付方式选择
    var oSelWeekDay = $('.js_selWeekDay');  // 日期选择
    var $texRi = $('.addInvoiceMess > .texRi');
    var oBllingText = $('.js_billingText');      // 发票信息展示
    $("#orderForm").eq(0).find("input[name='prepaidCard']").val("false");
    var lazLoading = new myPub.lazLoadingImg();
    var $submitBtn = $(".js_btnPay");                               // 提交支付按钮
    var oFullGroup = $('.js_fullGroup');                            // 拼单已满提示弹窗
    var oFullGroupCancle = $('.js_fullGroupCancle');                // 弹窗取消按钮
    var oFullGroupNow = $('.js_fullGroupNow');                      // 弹窗立即拼单按钮
    var oShowNum = $('.js_showNum');                                // 显示手机号码眼睛
    var oPhoneNum = $('.js_phoneNum');                              // 全部手机号码
    var oHidePhoneNUm = $('.js_hidePhoneNUm');                      // 隐藏手机号码
    var nPhoneNum = oPhoneNum.text();
    var nHideNum = nPhoneNum.substr(0,3)+'****'+nPhoneNum.substr(7,11);


    module.exports = {
        init: function(data,names){
            lazLoading.AddLazLoadingImg(oWrap[0]);
            payType.choosePayType();
            if(isJifen==true && canBuy == false && pointCost != null && pointCost != undefined && pointCost != ""){
                myPub.TipLayerLong("抱歉，该商品兑换须"+pointCost+"积分，您的积分暂未达到兑换条件，请继续努力哦！~");
            }
            if(errAddress  && errAddress != ''){
                myPub.TipLayerLong(errAddress);
            }
            if(addressOutofProvince&& addressOutofProvince!=''){
                    myPub.TipLayerLong(addressOutofProvince);
            }
            // 优惠券三期
            if(isJifen==false) {
                coupon.initCoupon();
            }
        }
    };

    // 手机号码隐藏
    oHidePhoneNUm.text(nHideNum);
    oShowNum.on('click',function (e) {
        if($(this).hasClass('on')){
            oPhoneNum.hide();
            oHidePhoneNUm.show();
            $(this).removeClass('on icon-eye_look').addClass('icon-eye_close')
        }else{
            oHidePhoneNUm.hide();
            oPhoneNum.show();
            $(this).addClass('on icon-eye_look').removeClass('icon-eye_close')
        }
        e.stopPropagation();
    });

    oMyPayType.hammer().on('tap', function () {
        var index = $(this).index()
        oMyPayType.find('.js_checkBox').removeClass('active').eq(index).addClass('active');
        var payType = oMyPayType.eq(index).attr("data-payType");
            if(oBllingText.hasClass("noInvoiceSupport")){
                oBllingText.html("添加发票信息");
                oBllingText.removeClass("noInvoiceSupport");
            }
            $texRi.show();
        priceCount.choosePayType(payType);
    });

    // 拼团已满提示弹窗点击取消按钮
    oFullGroupCancle.on('click',function (e) {
        myPub.locationHref("/GroupBuying/goods/" + goodsSn);
        oFullGroup.hide();
        e.stopPropagation();
    });

    // 拼团已满提示弹窗点击立即拼单按钮
    oFullGroupNow.on('click',function (e) {
        oFullGroup.hide();
        $submitBtn.click();
        e.stopPropagation();
    });


    oSelWeekDay.find('li').hammer().on('tap', function () {
        var index = $(this).index()
        oSelWeekDay.find('li').removeClass('active').eq(index).addClass('active');
    });

    var payType = {
        choosePayType : function () {
            oMyPayType.find('.js_checkBox').removeClass('active').eq(0).addClass('active');
            var payType = oMyPayType.eq(0).attr("data-payType");
            priceCount.choosePayType(payType);
        },
    };

});